namespace Maple.Branch.Tenants.TestDatas
{
    using System.Threading.Tasks;
    using Entities;
    using IRepositories;
    using IServices;
    using Volo.Abp.DependencyInjection;

    public class TenantsTestDataBuilder : ITransientDependency
    {
        private readonly ITenantRepository _tenantRepository;
        private readonly ITenantManager _tenantManager;

        public TenantsTestDataBuilder(
            ITenantRepository tenantRepository,
            ITenantManager tenantManager)
        {
            _tenantRepository = tenantRepository;
            _tenantManager = tenantManager;
        }

        public async Task SeedAsync()
        {
            await AddTenantsAsync();
        }

        private async Task AddTenantsAsync()
        {
            var acme = await _tenantManager.CreateAsync("acme");
            acme.ConnectionStrings.Add(new TenantConnectionString(acme.Id, Volo.Abp.Data.ConnectionStrings.DefaultConnectionStringName, "DefaultConnString-Value"));
            acme.ConnectionStrings.Add(new TenantConnectionString(acme.Id, "MyConnString", "MyConnString-Value"));
            await _tenantRepository.InsertAsync(acme);

            var volosoft = await _tenantManager.CreateAsync("volosoft");
            await _tenantRepository.InsertAsync(volosoft);
        }
    }
}
